home *** CD-ROM | disk | FTP | other *** search
- {*********************************************************}
- {* AAHpMin *}
- {* Copyright (c) Julian M Bucknall 2000 *}
- {* All rights reserved. *}
- {*********************************************************}
- {* Algorithms Alfresco: Minimum heap replacement *}
- {*********************************************************}
-
- {Note: this unit is released as freeware. In other words, you are free
- to use this unit in your own applications, however I retain all
- copyright to the code. JMB}
-
- unit AAHpMin;
-
- {WARNING: this unit *must* appear first in your project's uses list.}
-
- interface
-
- implementation
-
- uses
- Windows; // it's OK to use the Windows unit: it allocates no memory
-
- var
- OrigHeap : TMemoryManager;
- OurHeap : TMemoryManager;
-
- function OurGetMem(Size : integer) : pointer;
- begin
- Result := OrigHeap.GetMem(Size);
- end;
-
- function OurFreeMem(P : pointer) : integer;
- begin
- Result := OrigHeap.FreeMem(P);
- end;
-
- function OurReallocMem(P : pointer; Size : integer) : pointer;
- begin
- Result := OrigHeap.ReallocMem(P, Size)
- end;
-
- procedure InitializeUnit;
- begin
- {get the original manager}
- GetMemoryManager(OrigHeap);
-
- {set up our heap manager}
- OurHeap.GetMem := OurGetMem;
- OurHeap.FreeMem := OurFreeMem;
- OurHeap.ReallocMem := OurReallocMem;
-
- {replace heap manager with ours}
- SetMemoryManager(OurHeap);
- end;
-
- procedure FinalizeUnit;
- begin
- {restore the original manager}
- SetMemoryManager(OrigHeap);
- end;
-
-
- initialization
- InitializeUnit;
-
- finalization
- FinalizeUnit;
-
- end.
-